import os
import shutil

filelist = os.listdir("./imae")

def caozuo(name):
    sum = 0
    lxname = 0
    lx = ['.jpeg', '.png', '.gif', '.bmp', '.jpg']
    for i in filelist:
        if os.path.splitext(i)[1].lower() in lx:
            shutil.copyfile("./imae//" + i, f"./{name}//" + i)
            sum += 1
            if i[-4:] == '.jpg':
                try:
                    os.rename(f'./{name}//' + i, f'./{name}//第{lxname}个.jpg')
                except FileExistsError:
                    pass
                lxname += 1
    return sum


while 1:
    try:
        name = input("请输入文件夹名：")
        os.mkdir(name)
        print(f"共计拷贝{caozuo(name)}个文件")
        break
    except FileExistsError:
        print("已有文件名")
